//
//  ZCSAlbumSetTableViewCell.m
//  聆听FM
//
//  Created by dllo on 16/6/17.
//  Copyright © 2016年 Dark. All rights reserved.
//

#import "ZCSAlbumSetTableViewCell.h"

#import "ZCSLabelCollectionViewCell.h"

@implementation ZCSAlbumSetTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        UIView *cvBackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0 , self.frame.size.width, self.frame.size.height)];
        cvBackView.backgroundColor = [UIColor colorWithWhite:0.259 alpha:1.000];
        self.cvBackView = cvBackView;
        
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.itemSize = CGSizeMake((SCREENWIDTH - 110 * FITWIDTH) / 4, 25 * FITHEIGHT);
        flowLayout.minimumLineSpacing = 10 * FITHEIGHT;
        flowLayout.minimumInteritemSpacing = 30 * FITWIDTH;
        flowLayout.sectionInset = UIEdgeInsetsMake(10 * FITHEIGHT, 10 * FITWIDTH, 10 * FITHEIGHT, 10 * FITWIDTH);
        self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 0) collectionViewLayout:flowLayout];
        self.collectionView.backgroundColor = [UIColor whiteColor];
        self.collectionView.delegate = self;
        self.collectionView.dataSource = self;
        [cvBackView addSubview:_collectionView];
        
        [self.collectionView registerNib:[UINib nibWithNibName:@"ZCSLabelCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"labelCell"];
        [self addSubview:cvBackView];
    }
    return self;
}
- (void)setTotalCount:(NSInteger)totalCount
{
    _totalCount = totalCount;
    NSInteger tempNum = totalCount / 20 + 1;
    NSInteger num = tempNum / 4;
    CGFloat tempFloat = tempNum / 4.0;
    CGFloat height;
    if (tempFloat - num) {
        height = 25 * (num + 1) + 10 * (num + 2);
    }
    else
    {
        height = 25 * num + 10 * (num + 1);
    }
    self.collectionView.frame = CGRectMake(0, 0, SCREENWIDTH, height * FITHEIGHT);
    self.cvBackView.frame = self.bounds;
    [self.collectionView reloadData];

}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.totalCount / 20 + 1;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ZCSLabelCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"labelCell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor colorWithWhite:0.894 alpha:1.000];
    NSInteger num = self.itemNum - 20 * indexPath.row;
    if (num / 20 > 0) {
        NSString *tempString = [NSString stringWithFormat:@"%ld~%ld", 20 * indexPath.row + 1, 20 * indexPath.row + 20];
        cell.itemLabel.text = tempString;
    }
    else
    {
        NSString *tempString = [NSString stringWithFormat:@"%ld~%ld", 20 * indexPath.row + 1, self.totalCount];
        cell.itemLabel.text = tempString;
    }
    
    if (indexPath.row == self.isSelect) {
        cell.backgroundColor = [UIColor colorWithRed:1.00 green:0.30 blue:0.24 alpha:1.00];
    }
    else
    {
        cell.backgroundColor = [UIColor colorWithRed:0.96 green:0.97 blue:0.98 alpha:1.00];
    }
    
    
    return cell;
}




- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
